package com.rxkj.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.rxkj.entity.gnss.GnssDeviceVO;
import com.rxkj.entity.rainwater.StationInfo;
import com.rxkj.entity.rainwater.WaterAndRainVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface StationManageMapper {


    @Select("select * from station where enabled = 1 order by orderid asc")
    @ResultType(StationInfo.class)
    List<StationInfo> getHdrtuStationInfo();

    @DS("hongdian")
    @Select("SELECT a.`ONLINE` status, a.SIGNAL signalInten, b.VOLTAGE voltage from dev_term_status a, biz_rain_current b WHERE a.TERM_SN = b.TERM_SN AND a.TERM_SN = #{termsn}")
    WaterAndRainVO getRtuDetailsByTermsn(@Param("termsn") String stcdcode);

    Long getGnssDevInfoTotal(@Param("areaCode") String areaCode, @Param("deviceName") String deviceName);

    List<StationInfo> getGnssDevInfo(@Param("areaCode") String areaCode, @Param("start") int start, @Param("end") int end, @Param("deviceName")String deviceName);

    @Select("select count(*) from station where enabled = 1")
    @ResultType(int.class)
    int getCountYs();

    @Select("SELECT COUNT(*) FROM `earth_disaster`.surf_device WHERE MAINDEVICEID IN (SELECT ID FROM `earth_disaster`.surf_maindevice WHERE USEFLAG = 1 AND SECTIONID IN ( " +
            "SELECT ID FROM `earth_disaster`.SECTION WHERE USEFLAG = 1 AND YHDID IN ( " +
            "SELECT ID FROM `earth_disaster`.HIDDENPOINT WHERE USEFLAG = 1 AND AREACODE = #{areaCode}))) " +
            "AND type = 1 ")
    @ResultType(int.class)
    int getCountGnss(@Param("areaCode") String areaCode);

}
